package com.qilu.pe.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qilu.pe.R;
import com.qilu.pe.dao.bean.ItemSetDetail;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class ItemDetail3Fragment extends Fragment {
    private RecyclerView rcv_sick_list;

    private SickListAdapter adapter;

    private ItemSetDetail detail;

    public ItemDetail3Fragment() {

    }

    public static ItemDetail3Fragment newInstance(String param1, ItemSetDetail detail) {
        ItemDetail3Fragment fragment = new ItemDetail3Fragment();
        Bundle args = new Bundle();
        args.putSerializable("detail", detail);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        detail = (ItemSetDetail) getArguments().getSerializable("detail");
        adapter = new SickListAdapter(getActivity());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_item_detail3, container, false);
        rcv_sick_list = v.findViewById(R.id.rcv_sick_list);

        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        rcv_sick_list.setLayoutManager(manager);
        rcv_sick_list.setAdapter(adapter);
        adapter.setDataList(detail.getIllness());

        return v;
    }

    private class SickListAdapter extends ListBaseAdapter<ItemSetDetail.Illness> {

        public SickListAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_detail_sick_list;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_ill_name = holder.getView(R.id.tv_ill_name);
            TextView tv_ill_desc = holder.getView(R.id.tv_ill_desc);
            ItemSetDetail.Illness ill = mDataList.get(position);

            tv_ill_name.setText(ill.getName());
            tv_ill_desc.setText(ill.getManifestation());
        }
    }
}